package com.store.app.adapter;

import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;

import com.store.app.R;
import com.store.app.bean.ShoppingInfo;

import java.util.List;

/**
 * Created by lushan
 * on 2016/5/15 17:50 .
 */
public class ConfirmPaymentAdapter extends BaseAdapter {
    private Context context;
    //商品的bean
    private List<ShoppingInfo> shoppingInfoList;
    private LinearLayoutManager linearLayoutManager;
    private DefaultItemAnimator defaultItemAnimator;
    private SpaceItemDecoration spaceItemDecoration;
    public ConfirmPaymentAdapter(Context c,List<ShoppingInfo> shoppingInfoList) {
        this.context = c;
        this.shoppingInfoList=shoppingInfoList;
        linearLayoutManager = new LinearLayoutManager(context);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        defaultItemAnimator=new DefaultItemAnimator();
        spaceItemDecoration=new SpaceItemDecoration(8);
    }

    @Override
    public int getCount() {
        return shoppingInfoList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_confirmpayment, null);
            holder.item_confir_storename = (TextView) convertView.findViewById(R.id.item_confir_storename);
            holder.item_confir_goodnum = (TextView) convertView.findViewById(R.id.item_confir_goodnum);
            holder.item_confir_recyclerview = (RecyclerView) convertView.findViewById(R.id.item_confir_recyclerview);
            //设置布局管理器
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
            linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
             holder.item_confir_recyclerview.setLayoutManager(linearLayoutManager);
            holder.item_confir_recyclerview.setItemAnimator(defaultItemAnimator);
            holder.item_confir_recyclerview.addItemDecoration(spaceItemDecoration);//设置间距
            holder.item_confir_remark = (EditText) convertView.findViewById(R.id.item_confir_remark);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        ShoppingInfo shoppingInfo=shoppingInfoList.get(position);

        Confirpay_RecyclerAdapter confirpayRecyclerAdapter = new Confirpay_RecyclerAdapter(shoppingInfo.getBookedBeanList(), context);
        holder.item_confir_recyclerview.setAdapter(confirpayRecyclerAdapter);
        holder.item_confir_storename.setText(shoppingInfo.getSupplierName());
        holder.item_confir_goodnum.setText("共"+shoppingInfo.getBookedBeanList().size()+"件");
        return convertView;
    }




    public static class ViewHolder {
        public View rootView;
        public TextView item_confir_storename;
        public TextView item_confir_goodnum;
        public RecyclerView item_confir_recyclerview;
        public EditText item_confir_remark;


    }
    public class SpaceItemDecoration extends RecyclerView.ItemDecoration{

        private int space;

        public SpaceItemDecoration(int space) {
            this.space = space;
        }

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {

        }
    }
}
